
package org.apache.solr.handler.admin;

import java.io.IOException;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.handler.RequestHandlerBase;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.SolrQueryResponse;

/**
 * @since solr 1.2
 */
public class PropertiesRequestHandler extends RequestHandlerBase {

    @Override
    public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws IOException {

        Object props;
        String name = req.getParams().get("name");
        if(name != null) {
            NamedList<String> p = new SimpleOrderedMap<>();
            p.add(name, System.getProperty(name));
            props = p;
        }
        else {
            props = System.getProperties();
        }
        rsp.add("system.properties", props);
        rsp.setHttpCaching(false);
    }

    // SolrInfoMBeans methods
    @Override
    public String getDescription() {
        return "Get System Properties";
    }

    @Override
    public String getSource() {
        return "$URL:$";
    }
}
